# coding=utf8
__author__ = 'valux'
__mail__ = 'valux@qq.com'


class Compare(object):
    def __init__(self, rank):
        self.rank = rank
        pass

    def __cmp__(self, other):
        if self.rank == other.rank:
            return 0
        if self.rank < other.rank:
            return 1
        if self.rank > other.rank:
            return -1


class CompareSpec(object):
    def __init__(self, rank):
        self.rank = rank

    def __eq__(self, other):
        if self.rank > 5 and other.rank > 5:
            return True
        return False

    def __ne__(self, other):
        return self.rank != other.rank

    def __lt__(self, other):
        return self.rank < other.rank

    def __gt__(self, other):
        return self.rank > other.rank

    def __le__(self, other):
        return self.rank <= other.rank

    def __ge__(self, other):
        return self.rank >= other.rank



class CompareMix(object):
    """
        优先级比较
    """

    def __init__(self, rank):
        self.rank = rank

    def __eq__(self, other):
        print('__eq__')
        if self.rank > 5 and other.rank > 5:
            return True
        return False

    def __cmp__(self, other):
        print('__cmp__')
        if self.rank == other.rank:
            return 0
        if self.rank < other.rank:
            return -1
        if self.rank > other.rank:
            return 1

if __name__ == '__main__':
    l1 = Compare(1)
    l2 = Compare(2)

    print(l1 > l2)

    l3 = CompareSpec(6)
    l4 = CompareSpec(7)
    print(l3 == l4)

    l5 = CompareMix(4)
    l6 = CompareMix(4)
    print(l5 == l6)
